package com.meiyun.lisha

import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel

class MainActivity : FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    private fun initBackToDesktop(messenger: BinaryMessenger) {
        MethodChannel(messenger, CHANNEL).setMethodCallHandler { call, result ->
            if (call.method == eventBackDesktop) {
                moveTaskToBack(false);
                result.success(true)
            }
        }
    }

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        initBackToDesktop(flutterEngine.dartExecutor.binaryMessenger)

    }


    companion object {
        //通讯名称，回到手机桌面
        var CHANNEL = "android/back/desktop";

        //返回手机桌面事件
        var eventBackDesktop = "backDesktop";
    }
}
